package com.student.controller;

import com.student.bean.HealthNews;
import com.student.bean.User;
import com.student.service.AdminService;
import com.student.utils.AjaxResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;

@Controller
public class AdminController {
    @Resource
    private AdminService adminService;

    @ResponseBody
    @RequestMapping(value = "/selecctUser")
    public AjaxResult Alluser(@RequestParam(value = "loginname") String loginName){
        User user = adminService.selectUserByLoginName(loginName);
        return AjaxResult.getOk(user);
    }

    @ResponseBody
    @RequestMapping(value = "/releaseNews")
    public AjaxResult releaseNews(@RequestParam(value = "title") String title,
                                  @RequestParam(value = "summary") String summary,
                                  @RequestParam(value = "content") String content){
        HealthNews news = new HealthNews();
        news.setTitle(title);
        news.setSummary(summary);
        news.setContent(content);
        news.setDate(new Date());
        adminService.releaseNews(news);
        return AjaxResult.getOk("成功");
    }

    @ResponseBody
    @RequestMapping(value = "/allnews")
    public AjaxResult allnews(){
        return adminService.allnews();
    }

    @ResponseBody
    @RequestMapping(value = "/selecctUserAll")
    public AjaxResult selecctUserAll(@RequestParam("pageNum") Integer pageNum){
        return adminService.allUser(pageNum,5);
    }
}
